package com.chinasoft.maysham.manager.upgrade;

import com.chinasoft.maysham.manager.model.User;
import com.github.mongobee.changeset.ChangeLog;
import com.github.mongobee.changeset.ChangeSet;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@ChangeLog
public class ChangeLog1 {

    @ChangeSet(order = "001", id = "initAdminUser", author = "admin")
    public void initAdminUser(MongoTemplate template){
        boolean exists = template.exists(Query.query(Criteria.where("username").is("admin").and("deleted").is(false)), User.class);
        if (!exists){
            User user = new User();
            user.setUsername("admin");
            user.setNickName("超级管理员");
            user.setPassword("$2a$10$h1Xltxhd3n/SCYpaSfmPa.M1BFhe7jUa5yjAiNBleAaT5D3W3g092");
            template.save(user);
        }
    }
}
